<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/commons/taglibs.jsp"%>

<html>
	<head>
		<title>山西海宁皮革城</title>
		<%@ include file="/commons/meta.jsp"%>
		<script type="text/javascript">
		// 更新进度条
		//var progressFlagArray = new Array("false","false","false","false","false","false","false","false","false","false","false","false");
		var progressFlagArray = new Array(false,false,false,false,false,false,false,false,false,false,true);
		var progress = 6;
		
		
		$(document).ready(function(){
			
			/* setup navigation, content boxes, etc... */
			Administry.setup();
			
			/* progress bar animations - setting initial values */
			Administry.progress("#add_travel_progress", progress, 15);
			
			
			// validate form on keyup and submit
			var validator = $("#addTravelForm").validate({
				rules: {
					"travelAgencyName": {
						required: true,
					},
					"carNumber": {
						required: true,
					},
					"carType": {
						required: true,
					},
					"payType": {
						required: true,
					},
					"city": {
						required: true,
					},
					"viewpoint": {
						required: true,
					},
					"isContract": {
						required: true,
					},
					"remainTime": {
						required: true,
					},
					"isDedicated": {
						required: true,
					},
					"countPeople": {
						required: true,
						number: true,
					},
					"travelerPrice":{
						required: true,
						number: true,
					},
					"subsidyPrice":{
						required: true,
						number: true,
					}
				},
				messages: {
					"travelAgencyName": {
						required: "请输入旅行社名称",
					},
					"carNumber": {
						required: "请输入车牌号码",
					},
					"carType": {
						required: "请选择车型",
					},
					"payType": {
						required: "请选择付款方式",
					},
					"city": {
						required: "请出入城市",
					},
					"viewpoint": {
						required: "请输入景点",
					},
					"isContract": {
						required: "请选择是否签约",
					},
					"remainTime": {
						required: "请选择停留时间",
					},
					"isDedicated": {
						required: "请选择是否专线",
					},
					"countPeople": {
						required : "请输入人数",
						number: "请输入数字",
					},
					"travelerPrice":{
						required: "请输入人头补贴",
						number: "请输入合法数字",
					},
					"subsidyPrice":{
						required: "请输入司导补贴",
						number: "请输入合法数字",
					}
					
				},
				// the errorPlacement has to take the layout into account
				errorPlacement: function(error, element) {
					error.insertAfter(element.parent().find('label:first'));
				},
				// specifying a submitHandler prevents the default submit, good for the demo
				//submitHandler: function() {
				//	alert("Data submitted!");
				//},
				// set new class to error-labels to indicate valid fields
				success: function(label) {
					// set &nbsp; as text for IE
					label.html("&nbsp;").addClass("ok");
				}
			});								
			
				$("#travelAgencyName").blur(function() {
					var obj = $("#travelAgencyName");
					if(obj.val() !=""){
						if(progressFlagArray[0] != true){
							progress += 1;
							progressFlagArray[0] = true;
							Administry.progress("#add_travel_progress", progress, 15);
						}
					}else{
						if(progressFlagArray[0] == true){
							progress -= 1;
							progressFlagArray[0] = false;
							Administry.progress("#add_travel_progress", progress, 15);
						}
					}
				});
				$("#carNumber").blur(function() {
					var obj = $("#carNumber");
					if(obj.val() !=""){
						if(progressFlagArray[1] != true){
							progress += 1;
							progressFlagArray[1] = true;
							Administry.progress("#add_travel_progress", progress, 15);
						}
					}else{
						if(progressFlagArray[1] == true){
							progress -= 1;
							progressFlagArray[1] = false;
							Administry.progress("#add_travel_progress", progress, 15);
						}
					}
				});
				
				$("#carType").blur(function() {
					var obj = $("#carType");
//					var subsidyPrice = $("#subsidyPrice");
					if(obj.val() !=""){
						if(progressFlagArray[2] != true){
							progress += 1;
							progressFlagArray[2] = true;
							Administry.progress("#add_travel_progress", progress, 15);
						}
//						if(obj.val() =="0"){
//							subsidyPrice.val("100"); 
//						}
//						if(obj.val() =="1"){
//							subsidyPrice.val("200"); 
//						}
						
					}else{
						if(progressFlagArray[2] == true){
							progress -= 1;
							progressFlagArray[2] = false;
							Administry.progress("#add_travel_progress", progress, 15);
						}
						subsidyPrice.val(""); 
					}
				});
				
				$("#city").blur(function() {
					var obj = $("#city");
					if(obj.val() !=""){
						if(progressFlagArray[3] != true){
							progress += 1;
							progressFlagArray[3] = true;
							Administry.progress("#add_travel_progress", progress, 15);
						}
					}else{
						if(progressFlagArray[3] == true){
							progress -= 1;
							progressFlagArray[3] = false;
							Administry.progress("#add_travel_progress", progress, 15);
						}
					}
				});
				
				$("#viewpoint").blur(function() {
					var obj = $("#viewpoint");
					if(obj.val() !=""){
						if(progressFlagArray[4] != true){
							progress += 1;
							progressFlagArray[4] = true;
							Administry.progress("#add_travel_progress", progress, 15);
						}
					}else{
						if(progressFlagArray[4] == true){
							progress -= 1;
							progressFlagArray[4] = false;
							Administry.progress("#add_travel_progress", progress, 15);
						}
					}
				});
				
				$("#driver").blur(function() {
					var obj = $("#driver");
					if(obj.val() !=""){
						if(progressFlagArray[5] != true){
							progress += 1;
							progressFlagArray[5] = true;
							Administry.progress("#add_travel_progress", progress, 15);
						}
					}else{
						if(progressFlagArray[5] == true){
							progress -= 1;
							progressFlagArray[5] = false;
							Administry.progress("#add_travel_progress", progress, 15);
						}
					}
				});
				
				$("#guide").blur(function() {
					var obj = $("#guide");
					if(obj.val() !=""){
						if(progressFlagArray[6] != true){
							progress += 1;
							progressFlagArray[6] = true;
							Administry.progress("#add_travel_progress", progress, 15);
						}
					}else{
						if(progressFlagArray[6] == true){
							progress -= 1;
							progressFlagArray[6] = false;
							Administry.progress("#add_travel_progress", progress, 15);
						}
					}
				});
				
				$("#remainTime").blur(function() {
					var obj = $("#remainTime");
//					var travelerPrice = $("#travelerPrice");
//					var isDedicated = $("#isDedicated");
					if(obj.val() !=""){
						if(progressFlagArray[7] != true){
							progress += 1;
							progressFlagArray[7] = true;
							Administry.progress("#add_travel_progress", progress, 15);
						}
//						if(obj.val() =="0"){
//							if(isDedicated.val() == "0"){
//								travelerPrice.val("0"); 
//							}else if(isDedicated.val() == "1"){
//								travelerPrice.val("20"); 
//							}
//						}
//						if(obj.val() =="1"){
//							if(isDedicated.val() == "0"){
//								travelerPrice.val("18"); 
//							}else if(isDedicated.val() == "1"){
//								travelerPrice.val("38"); 
//							}
//						}
//						if(obj.val() =="2"){
//							if(isDedicated.val() == "0"){
//								travelerPrice.val("25"); 
//							}else if(isDedicated.val() == "1"){
//								travelerPrice.val("45"); 
//							}
//						}
//						if(obj.val() =="3"){
//							if(isDedicated.val() == "0"){
//								travelerPrice.val("35"); 
//							}else if(isDedicated.val() == "1"){
//								travelerPrice.val("55"); 
//							}
//						}
//						if(obj.val() =="4"){
//							if(isDedicated.val() == "0"){
//								travelerPrice.val("60"); 
//							}else if(isDedicated.val() == "1"){
//								travelerPrice.val("80"); 
//							}
//						}
					}else{
						if(progressFlagArray[7] == true){
							progress -= 1;
							progressFlagArray[7] = false;
							Administry.progress("#add_travel_progress", progress, 15);
						}
//						if(isDedicated.val() == "0"){
//							travelerPrice.val("0"); 
//						}else if(isDedicated.val() == "1"){
//							travelerPrice.val("20"); 
//						}
					}
				});
				
				$("#subsidyPrice").blur(function() {
					var obj = $("#subsidyPrice");
					if(obj.val() !=""){
						if(progressFlagArray[8] != true){
							progress += 1;
							progressFlagArray[8] = true;
							Administry.progress("#add_travel_progress", progress, 15);
						}
					}else{
						if(progressFlagArray[8] == true){
							progress -= 1;
							progressFlagArray[8] = false;
							Administry.progress("#add_travel_progress", progress, 15);
						}
					}
				});
				
				$("#travelerPrice").blur(function() {
					var obj = $("#travelerPrice");
					if(obj.val() !=""){
						if(progressFlagArray[9] != true){
							progress += 1;
							progressFlagArray[9] = true;
							Administry.progress("#add_travel_progress", progress, 15);
						}
					}else{
						if(progressFlagArray[9] == true){
							progress -= 1;
							progressFlagArray[9] = false;
							Administry.progress("#add_travel_progress", progress, 15);
						}
					}
				});
				
				$("#isDedicated").blur(function() {
					var obj = $("#isDedicated");
//					var remainTime = $("#remainTime");
//					var travelerPrice = $("#travelerPrice");
					if(obj.val() !=""){
						if(progressFlagArray[10] != true){
							progress += 1;
							progressFlagArray[10] = true;
							Administry.progress("#add_travel_progress", progress, 15);
						}
//						if(obj.val() =="0"){
//							if(remainTime.val() == "0"){
//								travelerPrice.val("0"); 
//							}else if(remainTime.val() == "1"){
//								travelerPrice.val("18"); 
//							}else if(remainTime.val() == "2"){
//								travelerPrice.val("25"); 
//							}else if(remainTime.val() == "3"){
//								travelerPrice.val("35"); 
//							}else if(remainTime.val() == "4"){
//								travelerPrice.val("60"); 
//							}
//						}
//						if(obj.val() =="1"){
//							if(remainTime.val() == "0"){
//								travelerPrice.val("20"); 
//							}else if(remainTime.val() == "1"){
//								travelerPrice.val("38"); 
//							}else if(remainTime.val() == "2"){
//								travelerPrice.val("45"); 
//							}else if(remainTime.val() == "3"){
//								travelerPrice.val("55"); 
//							}else if(remainTime.val() == "4"){
//								travelerPrice.val("80"); 
//							}
//						}
					}else{
						if(progressFlagArray[10] == true){
							progress -= 1;
							progressFlagArray[10] = false;
							Administry.progress("#add_travel_progress", progress, 15);
						}
					}
				});
				
			
		});
		
		
		// 验证账号重复
		$(function(){
			$("#getInfo").click(function(){
				$("#loading").html("正在加载中...");
				$.post(
					"prepareOpt!ajax.do",
					{travelAgencyName:$("#travelAgencyName").val()},
					
					function(data){
					//&& $("#txtVerifyCode").val().test(/^[a-z]+\w{2-5}@\w+.\w+.*\w*$/)
						if(data.ok ){
					//		$("#carNumber").val(data.carNumber);
					//		$("#carType").val(data.carType);
					//		$("#countPeople").val(data.countPeople);
							$("#city").val(data.city);
					//		$("#viewpoint").val(data.viewpoint);
							
					//		$("#isDriver").val(data.isDriver);
							
					//		$("#driver").val(data.driver);
					//		$("#guide").val(data.guide);
							
							$("#isContract").val(data.isContract);
							
					//		$("#remainTime").val(data.remainTime);
					//		$("#subsidyPrice").val(data.subsidyPrice);
					//		$("#travelerPrice").val(data.travelerPrice);
							
							$("#payType").val(data.payType);
							
					//		$("#totalPrice").val(data.totalPrice);
							
							$("#loading").html("加载完成");
						}else{
							$("#loading").html("基本信息中没有相关数据");
						}
					},
					"json"
				);
			});
		});
		
		var index=true;
		function valid(){
			var obj = $('#isDriver');
			var driver = $('#driver');
			var guide = $('#guide');
			var notInputDriver = $('#notInputDriver');
			var notInputGuide = $('#notInputGuide')
			if(driver.val() == "" && guide.val() == ""){
				index = false;
				if(obj.val() == "1"){
					notInputDriver.html("请输入司机");
					notInputGuide.html("");
				}else if(obj.val() == "0"){
					notInputGuide.html("请输入导游");
					notInputDriver.html("");
				}
			}else{
				index = true;
			}
			return  index;
		}
		
		
		</script>
	</head>

	<body>
		<%@ include file="/commons/top.jsp"%>
		<!-- Page title -->
		<div id="pagetitle">
			<div class="wrapper">
				<h1>Login Travel Agency Information</h1>
	            <a href="${ctx }/pages/travelAgencyInfo/add.jsp" class="btn"><span class="icon icon-add">&nbsp;</span>登记信息</a>
			</div>
		</div>
		<!-- End of Page title -->
		
		<!-- Page content -->
		<div id="page">
			<!-- Wrapper -->
			<div class="wrapper">
					<div id="add_travel_progress" class="progress full progress-green"><span><b></b></span></div>
					<!-- Left column/section -->
					<section class="column full first">					
						<form id="addTravelForm" method="post" action="travelOpt!addTravelAgencyInfo.do"  onsubmit="return valid()">
							<fieldset>
								<legend>登记旅行社信息</legend>
								
								<div style="float:left;width:28%;margin-right:5%;">
									<p>
										<label class="required" for="travelAgencyName">旅行社(<a href="#" id="getInfo" title="如果基本信息中有相关数据，输入旅行社名称，点击这里可以直接设置信息。" >加载基本信息</a>)：<span id="loading" style="color:#E9584C"></span></label><br/>
										<input type="text" id="travelAgencyName" class="full"  name="travelAgencyName"/>
									</p>
								</div>
								
								<div style="float:left;width:28%;margin-right:5%;">
									<p>
										<label class="required" for="carNumber">车牌号：</label><br/>
										<input type="text" id="carNumber" class="full"  name="carNumber"/>
										
									</p>
								</div>
								
								<div style="float:left;width:28%;margin-right:5%;">
									<p>
										<label class="required" for="carType">车型：</label><br/>
										<select id="carType" class="full"  name="carType">
											<option value="" selected>请选择车型</option>
											<option value="0" >中巴</option>
											<option value="1">大巴</option>
										</select>
									</p>
								</div>
								
								<div style="float:left;width:28%;margin-right:5%;clear:both;">
									<p>
										<label class="required" for="payType">付款方式：</label><br/>
										<select id="payType" class="full"  name="payType">
											<option value="0" selected>留存</option>
											<option value="1">现结</option>
										</select>
									</p>
								</div>
								
	
								<div style="float:left;width:28%;margin-right:5%;">
									<p>
										<label class="required" for="city">城市：</label><br/>
										<input type="text" id="city" class="full" name="city"/>
									</p>
								</div>
								
								<div style="float:left;width:28%;margin-right:5%;">
									<p>
										<label class="required" for="viewpoint">景点：</label><br/>
										<input type="text" id="viewpoint" class="full"  name="viewpoint"/>
									</p>
								</div>
								
								<div style="float:left;width:28%;margin-right:5%;clear:both;">
									<p>
										<label class="" for="isDriver">是否司机：</label><br/>
										<select id="isDriver" class="full"  name="isDriver">
											<option value="0" selected>否</option>
											<option value="1">是</option>
										</select>
									</p>
								</div>
								<div style="float:left;width:28%;margin-right:5%;">
									<p>
										<label class="" for="driver">司机<span id="driverRemark"></span>：<span id="notInputDriver" style="color:#E9584C"></span></label><br/>
										<input type="text" id="driver" class="full"  name="driver" />
									</p>
								</div>
								<div style="float:left;width:28%;margin-right:5%;">
									<p>
										<label class="" for="guide">导游<span id="guideRemark"></span>：<span id="notInputGuide" style="color:#E9584C"></span></label><br/>
										<input type="text" id="guide" class="full"  name="guide"/>
									</p>
								</div>
								
								<div style="float:left;width:28%;margin-right:5%;clear:both;">
									<p>
										<label class="required" for="isDedicated">联系方式：</label><br/>
										<input type="text" id="isDedicated" class="full"  name="isDedicated"/>									</p>
									
								</div>
								
								<div style="float:left;width:28%;margin-right:5%;">
									<p>
										<label class="required" for="isContract">签约：</label><br/>
										<select id="isContract" class="full"  name="isContract">
											<option value="0" selected>未签</option>
											<option value="1">已签</option>
										</select>
									</p>
									
								</div>
								<div style="float:left;width:28%;margin-right:5%;">
									<p>
										
										<label class="required" for="remainTime">停留时间：</label><br/>
										<input type="text" id="remainTime" class="full"  name="remainTime"/>	
										
									</p>
									
								</div>
								
								<div style="float:left;width:28%;margin-right:5%;clear:both;">
									<p>
										<label class="required" for="subsidyPrice">司导补贴：</label><br/>
										<input type="text" id="subsidyPrice" class="full"  name="subsidyPrice" />
									</p>
								</div>
								<div style="float:left;width:28%;margin-right:5%;">
									<p>
										<label class="required" for="travelerPrice">人头补贴：</label><br/>
										<input type="text" id="travelerPrice" class="full"   name="travelerPrice" />
									</p>
								</div>
								
								<div style="float:left;width:28%;margin-right:5%;">
								<p>
									<label class="required" for="countPeople">人数：</label><br/>
									<input type="text" id="countPeople" class="full" name="countPeople" value="0" />
								</p>
								</div>
								
								
								
								<div style="clear:both;padding-top:15px;">
									<p class="box"><input type="submit" class="btn btn-green big" value="添加"/> or <input type="reset" class="btn" value="重置"/></p>
								</div>
							</fieldset>
						</form>
						
						<div class="clear">&nbsp;</div>
						
					</section>
					<!-- End of Left column/section -->
					
					
			</div>
			<!-- End of Wrapper -->
		</div>							
		<!-- End of Page content -->
		
		<!-- Page footer -->
		<%@ include file="/commons/footer.jsp"%>
		<!-- End of Page footer -->
		
		<!-- Scroll to top link -->
		<a href="#" id="totop">^ scroll to top</a>
	
		<!-- User interface javascript load -->
		<script type="text/javascript" SRC="js/administry.js"></script>
		<script type="text/javascript">
			var obj = $('#isDriver');
			var driver = $('#driver');
			var guide = $('#guide');
			var driverRemark = $('#driverRemark');
			var guideRemark = $('#guideRemark');
			if(obj.val() == "0"){
				driver.val("");
				driver.attr("disabled", "disabled");
				guide.attr( "disabled", "");
				driverRemark.html("(已锁定)");
				guideRemark.html("");
				
			}else if(obj.val() == "1"){
				guide.val("");
				guide.attr( "disabled", "disabled");
				driver.attr( "disabled", "");
				guideRemark.html("(已锁定)");
				driverRemark.html("");
			}
		$('#isDriver').bind('change',function(){
			var obj = $('#isDriver');
			var driver = $('#driver');
			var guide = $('#guide');
			var driverRemark = $('#driverRemark');
			var guideRemark = $('#guideRemark');
			var notInputDriver = $('#notInputDriver');
			var notInputGuide = $('#notInputGuide')
			if(obj.val() == "0"){
				driver.val("");
				driver.attr("disabled", "disabled");
				guide.attr( "disabled", "");
				driverRemark.html("(已锁定)");
				guideRemark.html("");
				notInputGuide.html("请输入导游");
				notInputDriver.html("");
			}else if(obj.val() == "1"){
				guide.val("");
				guide.attr( "disabled", "disabled");
				driver.attr( "disabled", "");
				guideRemark.html("(已锁定)");
				driverRemark.html("");
				notInputDriver.html("请输入司机");
				notInputGuide.html("");
			}
		});
		</script>
	</body>
</html>
